import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class TEST {
    //斐波那契数列
    public static int fac(int n){
        if(n == 1||n == 2)
            return  n;
        return  fac(n-1)+fac(n-2);
    }
public  static  int fac1(int n){
        int f1 = 1;
        int  f2 = 1;
        int f3 = 0;
        for(int i = 3;i <=n;i++){
            f3 = f2 + f1;
            f1 = f2;
            f2 = f3;
        }
        return f3;
}
public static int[] transform(int[] arrarys){
        int[] ret = new int[arrarys.length];
    for (int i = 0; i <arrarys.length ; i++) {
         ret [i] = arrarys[i] * 2;
    }
    return ret;

}
    public static void main0(String[] args) {
        //数组扩大2倍
int[] arrays ={1,2,3,4,5,6};
        System.out.println(Arrays.toString(arrays));
        int[] tmp = transform(arrays);
        System.out.println(Arrays.toString(tmp));
//        System.out.println(fac1(7));;
    }
public static int binarysearch(int []arrays,int key){
        int left = 0;
        int right = arrays.length - 1;

        while(left<=right) {
            int mid = (right + left )/2;
            if (arrays[mid] > key) {
                right = mid - 1;
            } else if (arrays[mid] < key) {
                left = mid + 1;
            } else if (arrays[mid] == key) {
                System.out.println("找到了："+arrays[mid]);
                System.out.print("下标是: ");
                  return mid;
            }
        }

            return -1;
    }


    public static void main11(String[] args) {
        int [] arrays ={2,8,4,5,6,7,3,1};
       int ret =  binarysearch(arrays,7);
        System.out.println(ret);
    }
public static void changeNum(int[]arrays){
    for (int i = 0; i <arrays.length ; i++) {
        if(arrays[i] % 2 != 0){
        arrays[i] = arrays[i-1];
    }
}
    }

    public static void main66(String[] args) {
        int []arrays = {1,2,3,4,5,6,7,8};
        System.out.println(Arrays.toString(arrays));
        //交换后
        int[]tmp = new int[arrays.length];
        System.out.println(Arrays.toString(tmp));
    }
public static void my_bobblesort(int[] arrays){
        //i表示趟数
    for (int i = 0; i <arrays.length-1 ; i++) {
        boolean flg =false;
        for (int j = 0; j <arrays.length-1-i ; j++) {
            if(arrays[j]<arrays[j+1]){
                int tmp  = arrays[j];
                arrays[j] = arrays[j+1];
                arrays[j+1] = tmp;
                flg = true;
            }


        }
        if(flg == false)
            return ;

    }
}
    public static void main12(String[] args) {
        //冒泡排序
        int []arrarys = {1,2,3,4,5,6,7,8,9};
        System.out.println(Arrays.toString(arrarys));
       my_bobblesort(arrarys);
        System.out.println(Arrays.toString(arrarys));
    }
public static void fun66(int [] arrays){
        int left = 0;
        int right = arrays.length-1;
        while(left <right){
            if(left<right && arrays[left]%2 != 0){
                left++;
            }
            if(left<right && arrays[right]%2 == 0){
                right--;
            }

                int tmp = arrays[right];
                arrays[right] = arrays[left];
                arrays[left] = tmp;
        }

}
    public static void main(String[] args) {
        //奇数与偶数的区分
        int[]arrays = {2,4,3,1,5,9,8};
        System.out.println(Arrays.toString(arrays));
        System.out.print("交换后");
        fun66(arrays);
        System.out.println(Arrays.toString(arrays));
    }
public static int[] fac(int [] arrays,int target){
        int []ret =new int[] {-1,-1};
    for (int i = 0; i <arrays.length-1 ; i++) {
        for (int j = 0; j <arrays.length-1 ; j++) {
            if (arrays[i] + arrays[j] == target) {
                ret[0] = j;
                ret[1] = i;
            }

        }

    }
    return  ret;
    }



    public static void main23(String[] args) {
        //两数之和
        int []arrays = {2,7,11,15};
        int[]ret =fac(arrays,9);
        System.out.println(Arrays.toString(ret));
    }
public static int fun21(int []array){
        Arrays.sort(array);
        return  array.length/2;
}

    public static void main999(String[] args) {
        //多数元素
        int []array ={1,3,2,2,1};
        System.out.println(fun21(array));

    }
public static int fac2(int []array){
        int ret = 0;
    for (int i = 0; i <array.length; i++) {
        ret^=array[i];
    }
    return ret;
}
    public static void main00(String[] args) {
        //只出现一次的数字
        int []array = {4,1,2,1,2};
       int ret = fac2(array);
        System.out.println(ret);
    }
public static boolean fac4(int [] array){
      int  count = 0;
    for (int i = 0; i < array.length; i++) {
        if(array[i] %2 != 0){
            count++;
            if(count == 3){
                return true;
            }

        }else
            count = 0;


    }
    return  false;
}
    public static void main777(String[] args) {
        //连续三个奇数为真
        int []array1 = { 2,6,4,1};
        int []array2 = {1,2,23,3,4,5,7,23,12 };
        System.out.println(fac4(array1));
        System.out.println(fac4(array2));


    }
    public static double max4(double a,double b){
        return a > b ? a: b ;
    }
    public static double max3(double a,double b,double c){
        double ret = max4(a,b);
        double tmp = max4(ret,c);
return tmp;
    }

    public static void main5(String[] args) {
        System.out.println(max4(5.6,7.7));
        System.out.println(max3(9.9,56.3,9.1));

    }
    public static int sum(int a,int b){
        return  a+b;
    }
    public static double sum2(double a,double b,double c){
        return a+b+c;
    }
    public static void main3(String[] args) {
        System.out.println(sum(7,3));
        System.out.println(sum2(6.4,4.5,8));
    }
    public  static  int max(int a,int b){
        return a > b ? a: b ;
    }
public  static int max2(int a,int b,int c){
        int ret = max(a,b);
        int tmp = max(ret,c);
    return tmp;
}
    public static void main2(String[] args) {
        System.out.println(max2(51,12,54));

    }
    //猜数字小游戏
    public static void main1(String[] args) {
        Random random = new Random();
        int randNum = random.nextInt(100);
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("请输入数字");
            int num = scanner.nextInt();
            if(num < randNum){
                System.out.println("小了");
            }
            else if (num == randNum) {
                System.out.println("猜对了");
                break;
            }
            else if(num >randNum){
                System.out.println("大了");
            }
        }

    }


}

